package com.tool.tcp;

import org.come.until.Arith;

import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;


/**精灵*/
public class Sprite   //精灵 --小情调备注
//{
//    private int Use=0;//使用记录
//    private int load=-1;
//    private Frame[] frames;
//    private Frame currFrame;// 当前帧
//    private int animCount;//方向数
//    private int frameCount;//帧数
//    private int refPixelX;
//    private int refPixelY;
//    private int hightMax;//最高距离
//    private SpriteHead head;
//    public Sprite(Image image) {
//        // TODO Auto-generated constructor stub
//        frames=new Frame[1];
//        frames[0]=new Frame(image,0,0);
//        currFrame=frames[0];
//        animCount=1;
//        frameCount=1;
//    }
//    public Sprite(Frame[] frames, int animCount, int frameCount,SpriteHead head,int refPixelX,int refPixelY) {
//        super();
//        this.frames = frames;
//        this.currFrame=frames[0];
//        this.animCount = animCount;
//        this.frameCount = frameCount;
//        this.head = head;
//        this.refPixelX=refPixelX;
//        this.refPixelY=refPixelY;
//    }
//    public boolean contains(int x, int y) {
//        try {
//            if (currFrame.getImage()==null) {return false;}
//            Image bi=currFrame.getImage();
//            if (currFrame.getPos()!=0) {
//                x=currFrame.getRefPixelX()-x;
//            }else {
//                x+=currFrame.getRefPixelX();
//            }
//            y+=currFrame.getRefPixelY();
//            if ((x >= 0 && x < bi.getWidth(null)) && (y >= 0 && y < bi.getHeight(null))) {
//                if (bi instanceof BufferedImage) {
//                    BufferedImage bimage = (BufferedImage) bi;
//                    return bimage.getRGB(x, y) != 0;
//                } else {
//                    return true;
//                }
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return false;
//    }
//    private static AffineTransform transform=new AffineTransform();
//    public void draw(Graphics g, int x, int y) {
//        if (currFrame.getImage()!=null) {
//            Graphics2D g2 = (Graphics2D)g;
//            if (currFrame.getPos()==0) {
//                x -= currFrame.getRefPixelX();
//                y -= currFrame.getRefPixelY();
//                g2.drawImage(currFrame.getImage(), x, y,currFrame.getWidth(),currFrame.getHeight(), null);
//                //消除文字锯齿
//                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//                //消除画图锯齿
//                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//            }else {//反向绘制
//                x += currFrame.getRefPixelX();
//                y -= currFrame.getRefPixelY();
//                transform.setToIdentity();
//                transform.scale(-1, 1);
//                transform.translate(-x  , y);
//                g2.drawImage(currFrame.getImage(),transform,null);
//                //消除文字锯齿
//                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//                //消除画图锯齿
//                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//            }
//        }
//    }
//    //飞行器相关
//    public void drawfly(Graphics g, int x, int y) {
//        if (currFrame.getImage()!=null) {
//            if (currFrame.getPos()==0) {
//                x -= currFrame.getRefPixelX();
//                y -= currFrame.getRefPixelY();
//                g.drawImage(currFrame.getImage(), x, y,currFrame.getWidth(),currFrame.getHeight(), null);
//            }else {//反向绘制
//                Graphics2D g2 = (Graphics2D)g;
//                x += currFrame.getRefPixelX();
//                y -= currFrame.getRefPixelY();
//                transform.setToIdentity();
//                transform.scale(-1, 1);
//                transform.translate(-x  , y);
//                g2.drawImage(currFrame.getImage(),transform,null);
//            }
//        }
//    }
//    public void drawflyShadow(Graphics g, int x, int y) {
//        if (currFrame.getImage()!=null) {
//            if (currFrame.getPos()==0) {
//                x -= currFrame.getRefPixelX();
//                y -= currFrame.getRefPixelY();
//                g.drawImage(currFrame.getImage(), x, y,currFrame.getWidth(),currFrame.getHeight(), null);
//            }else {//反向绘制
//                Graphics2D g2 = (Graphics2D)g;
//                x += currFrame.getRefPixelX();
//                y -= currFrame.getRefPixelY();
//                transform.setToIdentity();
//                transform.scale(-1, 1);
//                transform.translate(-x  , y);
//                g2.drawImage(currFrame.getImage(),transform,null);
//            }
//        }
//    }
//    public static AlphaComposite Composite06=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.6f);
//    public void draw(Graphics g, int x, int y, float alpha) {
//        Graphics2D g2 = (Graphics2D) g;
//        if (alpha==1.0F) {
//            draw(g2, x, y);
//        }else {
//            Composite composite =null;
//            try {
//                if (alpha==0.6f) {
//                    composite =g2.getComposite();
//                    g2.setComposite(Composite06);
//                }else {
//                    composite =g2.getComposite();
//                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha));
//                }
//                draw(g2, x, y);
//            } catch (Exception e) {
//                // TODO: handle exception
//                e.printStackTrace();
//            } finally {
//                if (composite!=null) {
//                    g2.setComposite(composite);
//                }
//            }
//            //消除文字锯齿
//            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//            //消除画图锯齿
//            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//        }
//    }
//    public void updateToTime(long playTime,int dir){
//        try {
//            if (playTime<0) {
//                playTime%=getTime();
//                playTime+=getTime();
//            }
//            Use=1;
//            dir%=animCount;
//            playTime/=SpriteFactory.ANIMATION_INTERVAL;
//            playTime%=frameCount;
//            currFrame=frames[(int)(dir*frameCount+playTime)];
//            if (load==-1&&currFrame.getImage()==null) {
//                load=dir;
//                SpriteFactory.addLoad(this);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//    public int getAnimationCount() { return animCount; }
//    public int getFrameCount() { return frameCount; }
//    public int getTime() { return frameCount*SpriteFactory.ANIMATION_INTERVAL; }
//    public SpriteHead getHead() { return head; }
//    public void setHead(SpriteHead head) { this.head = head; }
//    public int getLoad() { return load; }
//    public void setLoad(int load) { this.load = load; }
//    public Frame getLoadFrame(int dir) { return frames[dir*frameCount]; }
//    public Frame[] getFrames() { return frames; }
//    public void removeHead() { //都加载完了 就清除
//        this.load=-1;
//        for (int i = 0; i < frames.length; i++) {
//            if (frames[i].getImage()==null) {setHightMax();return;}
//        }
//        this.head.remve();
//        this.head=null;
//        setHightMax();
//    }
//    public void setHightMax() {
//        int max=-99999;
//        for (int i = 0; i < frames.length; i++) {
//            Frame frame=frames[i];
//            if (frame.getImage()==null) { continue; }
//            if (frame.getRefPixelY()+frame.getHeight()>max) { max=frame.getRefPixelY()+frame.getHeight(); }
//        }
//        if (max==-99999) { max=0; }
//        hightMax=max;
//        if (hightMax>=200) { hightMax-=110; }
//    }
//    public int getHightMax() { return hightMax; }
//    public int getUse() { return Use; }
//    public void setUse(int use) { Use = use; }
//    public Frame getCurrFrame() { return currFrame; }
//    public int getRefPixelX() { return refPixelX; }
//    public int getRefPixelY() { return refPixelY; }
//    /**旋转共用*/
//    public void translate(int dir1,int dir2) {
//        for (int i = 0; i < frameCount; i++) {
//            Frame frame=frames[dir1*frameCount+i];
//            Frame frame2=frames[dir2*frameCount+i];
//            frame2.setImage(frame.getImage(),frame.getRefPixelX(),frame.getRefPixelY());
//        }
//    }
//
//    public void draw(Graphics g, int x, int y, String skillid) {
//
//
//        if(GetTcpPath.STRTMPXJ!=null) {
//            if(GetTcpPath.STRTMPXJ.equals("1")) {//新版法术
//
//                if (this.currFrame.getImage() != null) {
//                    if (this.currFrame.getPos() == 0) {
//                        x -= this.currFrame.getRefPixelX();
//                        y -= this.currFrame.getRefPixelY();
//                        Image image = this.currFrame.getImage();
//                        if ((skillid.contains("1045.")) || (skillid.contains("1050.")) || (skillid.contains("1020.")) || (skillid.contains("1040.")) || (skillid.contains("1025."))) {
//                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
//                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
//                            if(skillid.contains("1050.")) {
//                            }
//                            System.out.println(x+"--"+y);
//                            if(x>0) {
//                                x = x;
//                            }
//                            g.drawImage(image, x, y, width, height, null);
//                        } else if ( (skillid.contains("1015.")) || (skillid.contains("1010."))) {
//                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
//                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
//                            g.drawImage(image, x, y, width, height, null);
//                        } else if (skillid.contains("1030.tcp")) {
//                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
//                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
//                            g.drawImage(image, x, y, width, height, null);
//                        } else {
//                            g.drawImage(image, x, y, this.currFrame.getWidth(), this.currFrame.getHeight(), null);
//                        }
//                    } else {
//                        Graphics2D g2 = (Graphics2D)g;
//                        x += this.currFrame.getRefPixelX();
//                        y -= this.currFrame.getRefPixelY();
//                        transform.setToIdentity();
//                        transform.scale(-1.0D, 1.0D);
//                        transform.translate(-x, y);
//                        g2.drawImage(this.currFrame.getImage(), transform, null);
//                    }
//                }
//
//            }else {//旧版法术
//                if (this.currFrame.getImage() != null) {
//                    if (this.currFrame.getPos() == 0) {
//                        x -= this.currFrame.getRefPixelX();
//                        y -= this.currFrame.getRefPixelY();
//                        Image image = this.currFrame.getImage();
//                        if ((skillid.contains("1045.")) || (skillid.contains("1050.")) || (skillid.contains("1020.")) || (skillid.contains("1040.")) || (skillid.contains("1025."))) {
//                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
//                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
//                            if(skillid.contains("1050.")) {
//                            }
//                            System.out.println(x+"--"+y);
//                            if(x>0) {
//                                x = x;
//                            }
//                            g.drawImage(image, x, y, width, height, null);
//                        } else if ( (skillid.contains("1015.")) || (skillid.contains("1010."))) {
//                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
//                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
//                            g.drawImage(image, x, y, width, height, null);
//                        } else if (skillid.contains("1030.tcp")) {
//                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
//                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
//                            g.drawImage(image, x, y, width, height, null);
//                        } else {
//                            g.drawImage(image, x, y, this.currFrame.getWidth(), this.currFrame.getHeight(), null);
//                        }
//                    } else {
//                        Graphics2D g2 = (Graphics2D)g;
//                        x += this.currFrame.getRefPixelX();
//                        y -= this.currFrame.getRefPixelY();
//                        transform.setToIdentity();
//                        transform.scale(-1.0D, 1.0D);
//                        transform.translate(-x, y);
//                        g2.drawImage(this.currFrame.getImage(), transform, null);
//                    }
//                }
//
//            }
//        }
//    }
//}

{
/*//    345字体模糊，替换整个文件可以完美解决
    private int Use=0;//使用记录
    private int load=-1;
    private Frame[] frames;
    private Frame currFrame;// 当前帧
    private int animCount;//方向数
    private int frameCount;//帧数
    private int refPixelX;
    private int refPixelY;
    private int hightMax;//最高距离
    private SpriteHead head;
    private Boolean highlight;
    private long playedFrameCount = 0;

    private Integer leixing = -1;
    public Sprite(Image image) {
        // TODO Auto-generated constructor stub
        frames=new Frame[1];
        frames[0]=new Frame(image,0,0);
        currFrame=frames[0];
        animCount=1;
        frameCount=1;
    }
    public Sprite(Frame[] frames, int animCount, int frameCount, SpriteHead head, int refPixelX, int refPixelY, boolean b) {
        super();
        this.frames = frames;
        this.currFrame=frames[0];
        this.animCount = animCount;
        this.frameCount = frameCount;
        this.head = head;
        this.refPixelX=refPixelX;
        this.refPixelY=refPixelY;
        this.highlight = b;
    }
    public boolean contains(int x, int y) {
        try {
            if (currFrame.getImage()==null) {return false;}
            Image bi=currFrame.getImage();
            if (currFrame.getPos()!=0) {
                x=currFrame.getRefPixelX()-x;
            }else {
                x+=currFrame.getRefPixelX();
            }
            y+=currFrame.getRefPixelY();
            if ((x >= 0 && x < bi.getWidth(null)) && (y >= 0 && y < bi.getHeight(null))) {
                if (bi instanceof BufferedImage) {
                    BufferedImage bimage = (BufferedImage) bi;
                    return bimage.getRGB(x, y) != 0;
                } else {
                    return true;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    private static AffineTransform transform=new AffineTransform();
    public void draw(Graphics g, int x, int y) {
        Graphics2D g2 = (Graphics2D) g.create();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        if (currFrame.getImage() != null) {
            if (currFrame.getPos() == 0) {
                x -= currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                g2.drawImage(currFrame.getImage(), x, y, currFrame.getWidth(), currFrame.getHeight(), null);
//                g.drawImage(currFrame.getImage(), x, y,(int)(currFrame.getWidth() * 0.95),(int)(currFrame.getHeight() * 0.95), null);
            } else {//反向绘制
                x += currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                transform.setToIdentity();
                transform.scale(-1, 1);
                transform.translate(-x, y);
                g2.drawImage(currFrame.getImage(), transform, null);
            }
        }
    }
    //飞行器相关
    public void drawfly(Graphics g, int x, int y) {
        if (currFrame.getImage()!=null) {
            if (currFrame.getPos()==0) {
                x -= currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                g.drawImage(currFrame.getImage(), x, y,currFrame.getWidth(),currFrame.getHeight(), null);
            }else {//反向绘制
                Graphics2D g2 = (Graphics2D)g;
                x += currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                transform.setToIdentity();
                transform.scale(-1, 1);
                transform.translate(-x  , y);
                g2.drawImage(currFrame.getImage(),transform,null);
            }
        }
    }
    public void drawflyShadow(Graphics g, int x, int y) {
        if (currFrame.getImage()!=null) {
            if (currFrame.getPos()==0) {
                x -= currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                g.drawImage(currFrame.getImage(), x, y,currFrame.getWidth(),currFrame.getHeight(), null);
            }else {//反向绘制
                Graphics2D g2 = (Graphics2D)g;
                x += currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                transform.setToIdentity();
                transform.scale(-1, 1);
                transform.translate(-x  , y);
                g2.drawImage(currFrame.getImage(),transform,null);
            }
        }
    }
    public static AlphaComposite Composite06=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.6f);
    public void draw(Graphics g, int x, int y, float alpha) {
        Graphics2D g2 = (Graphics2D) g;
        if (alpha==1.0F) {
            draw(g2, x, y);
        }else {
            Composite composite =null;
            try {
                if (alpha==0.6f) {
                    composite =g2.getComposite();
                    g2.setComposite(Composite06);
                }else {
                    composite =g2.getComposite();
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha));
                }
                draw(g2, x, y);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            } finally {
                if (composite!=null) {
                    g2.setComposite(composite);
                }
            }
            //消除文字锯齿
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            //消除画图锯齿
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        }
    }


    public void updateToTime(long playTime, int dir, Boolean b) {
        try {
            if (playTime<0) {
                playTime%=getTime();
                playTime+=getTime();
            }
            Use=1;
            dir%=animCount;
            playTime/=SpriteFactory.ANIMATION_INTERVAL;
            playTime%=frameCount;
            if (playedFrameCount < (frameCount -1)) {
                playedFrameCount = playTime %= frameCount;
            }else{
                return;
            }
            currFrame=frames[(int)(dir*frameCount+playTime)];
            if (load==-1&&currFrame.getImage()==null) {
                load=dir;
                SpriteFactory.addLoad(this);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void updateToTime(long playTime,int dir){
        try {
            if (playTime<0) {
                playTime%=getTime();
                playTime+=getTime();
            }
            Use=1;
            dir%=animCount;
            playTime/=SpriteFactory.ANIMATION_INTERVAL;
      //      playTime/=leixing != -1 ? 50 :SpriteFactory.ANIMATION_INTERVAL;
            playTime%=frameCount;
            currFrame=frames[(int)(dir*frameCount+playTime)];
            if (load==-1&&currFrame.getImage()==null) {
                load=dir;
                SpriteFactory.addLoad(this);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getAnimationCount() { return animCount; }
    public int getFrameCount() { return frameCount; }
    public int getTime() { return frameCount*SpriteFactory.ANIMATION_INTERVAL; }
    public SpriteHead getHead() { return head; }
    public void setHead(SpriteHead head) { this.head = head; }
    public int getLoad() { return load; }
    public void setLoad(int load) { this.load = load; }
    public Frame getLoadFrame(int dir) { return frames[dir*frameCount]; }
    public Frame[] getFrames() { return frames; }
    public void removeHead() { //都加载完了 就清除
        this.load=-1;
        for (int i = 0; i < frames.length; i++) {
            if (frames[i].getImage()==null) {setHightMax();return;}
        }
        this.head.remve();
        this.head=null;
        setHightMax();
    }
    public void setHightMax() {
        int max=-99999;
        for (int i = 0; i < frames.length; i++) {
            Frame frame=frames[i];
            if (frame.getImage()==null) { continue; }
            if (frame.getRefPixelY()+frame.getHeight()>max) { max=frame.getRefPixelY()+frame.getHeight(); }
        }
        if (max==-99999) { max=0; }
        hightMax=max;
        if (hightMax>=200) { hightMax-=110; }
    }
    public int getHightMax() { return hightMax; }
    public int getUse() { return Use; }
    public void setUse(int use) { Use = use; }
    public Frame getCurrFrame() { return currFrame; }
    public int getRefPixelX() { return refPixelX; }
    public int getRefPixelY() { return refPixelY; }
    *//**旋转共用*//*
    public void translate(int dir1,int dir2) {
        for (int i = 0; i < frameCount; i++) {
            Frame frame=frames[dir1*frameCount+i];
            Frame frame2=frames[dir2*frameCount+i];
            frame2.setImage(frame.getImage(),frame.getRefPixelX(),frame.getRefPixelY());
        }
    }

    public void draw(Graphics g, int x, int y, String skillid) {


        if(GetTcpPath.STRTMPXJ!=null) {
            if(GetTcpPath.STRTMPXJ.equals("1")) {//新版法术

                if (this.currFrame.getImage() != null) {
                    if (this.currFrame.getPos() == 0) {
                        x -= this.currFrame.getRefPixelX();
                        y -= this.currFrame.getRefPixelY();
                        Image image = this.currFrame.getImage();
                        if ((skillid.contains("1045.")) || (skillid.contains("1050.")) || (skillid.contains("1020.")) || (skillid.contains("1040.")) || (skillid.contains("1025."))) {
                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
                            if(skillid.contains("1050.")) {
                            }
                      //      System.out.println(x+"--"+y);
                            if(x>0) {
                                x = x;
                            }
                            g.drawImage(image, x, y, width, height, null);
                        } else if ( (skillid.contains("1015.")) || (skillid.contains("1010."))) {
                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
                            g.drawImage(image, x, y, width, height, null);
                        } else if (skillid.contains("1030.tcp")) {
                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
                            g.drawImage(image, x, y, width, height, null);
                        } else {
                            g.drawImage(image, x, y, this.currFrame.getWidth(), this.currFrame.getHeight(), null);
                        }
                    } else {
                        Graphics2D g2 = (Graphics2D)g;
                        x += this.currFrame.getRefPixelX();
                        y -= this.currFrame.getRefPixelY();
                        transform.setToIdentity();
                        transform.scale(-1.0D, 1.0D);
                        transform.translate(-x, y);
                        g2.drawImage(this.currFrame.getImage(), transform, null);
                    }
                }

            }else {//旧版法术
                if (this.currFrame.getImage() != null) {
                    if (this.currFrame.getPos() == 0) {
                        x -= this.currFrame.getRefPixelX();
                        y -= this.currFrame.getRefPixelY();
                        Image image = this.currFrame.getImage();
                        if ((skillid.contains("1045.")) || (skillid.contains("1050.")) || (skillid.contains("1020.")) || (skillid.contains("1040.")) || (skillid.contains("1025."))) {
                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
                            if(skillid.contains("1050.")) {
                            }
                      //      System.out.println(x+"--"+y);
                            if(x>0) {
                                x = x;
                            }
                            g.drawImage(image, x, y, width, height, null);
                        } else if ( (skillid.contains("1015.")) || (skillid.contains("1010."))) {
                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
                            g.drawImage(image, x, y, width, height, null);
                        } else if (skillid.contains("1030.tcp")) {
                            int width = (int)Arith.mul(this.currFrame.getWidth(), 1D);
                            int height = (int)Arith.mul(this.currFrame.getHeight(), 1D);
                            g.drawImage(image, x, y, width, height, null);
                        } else {
                            g.drawImage(image, x, y, this.currFrame.getWidth(), this.currFrame.getHeight(), null);
                        }
                    } else {
                        Graphics2D g2 = (Graphics2D)g;
                        x += this.currFrame.getRefPixelX();
                        y -= this.currFrame.getRefPixelY();
                        transform.setToIdentity();
                        transform.scale(-1.0D, 1.0D);
                        transform.translate(-x, y);
                        g2.drawImage(this.currFrame.getImage(), transform, null);
                    }
                }

            }
        }
    }

    public Boolean getHighlight() {
        return highlight;
    }

    public void setHighlight(Boolean highlight) {
        this.highlight = highlight;
    }

    public void draw(Graphics2D g2d, int i, int i1, int i2, long total, float v) {
    }


    public Integer getLeixing() {
        return leixing;
    }

    public void setLeixing(Integer leixing) {
        this.leixing = leixing;
    }*/
private int Use=0;//使用记录
    private int load=-1;
    private Frame[] frames;
    private Frame currFrame;// 当前帧
    private int animCount;//方向数
    private int frameCount;//帧数
    private int refPixelX;
    private int refPixelY;
    private int hightMax;//最高距离
    private SpriteHead head;
    public Sprite(Image image) {
        // TODO Auto-generated constructor stub
        frames=new Frame[1];
        frames[0]=new Frame(image,0,0);
        currFrame=frames[0];
        animCount=1;
        frameCount=1;
    }
    public Sprite(Frame[] frames, int animCount, int frameCount,SpriteHead head,int refPixelX,int refPixelY) {
        super();
        this.frames = frames;
        this.currFrame=frames[0];
        this.animCount = animCount;
        this.frameCount = frameCount;
        this.head = head;
        this.refPixelX=refPixelX;
        this.refPixelY=refPixelY;
    }
    public boolean contains(int x, int y) {
        try {
            if (currFrame.getImage()==null) {return false;}
            Image bi=currFrame.getImage();
            if (currFrame.getPos()!=0) {
                x=currFrame.getRefPixelX()-x;
            }else {
                x+=currFrame.getRefPixelX();
            }
            y+=currFrame.getRefPixelY();
            if ((x >= 0 && x < bi.getWidth(null)) && (y >= 0 && y < bi.getHeight(null))) {
                if (bi instanceof BufferedImage) {
                    BufferedImage bimage = (BufferedImage) bi;
                    return bimage.getRGB(x, y) != 0;
                } else {
                    return true;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    private static AffineTransform transform=new AffineTransform();
    public void draw(Graphics g, int x, int y) {
        if (currFrame.getImage()!=null) {
            Graphics2D g2 = (Graphics2D)g;
            if (currFrame.getPos()==0) {
                x -= currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                g2.drawImage(currFrame.getImage(), x, y,currFrame.getWidth(),currFrame.getHeight(), null);
                //消除文字锯齿
                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                //消除画图锯齿
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            }else {//反向绘制
                x += currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                transform.setToIdentity();
                transform.scale(-1, 1);
                transform.translate(-x  , y);
                g2.drawImage(currFrame.getImage(),transform,null);
                //消除文字锯齿
                g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                //消除画图锯齿
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            }
        }
    }
    //飞行器相关
    public void drawfly(Graphics g, int x, int y) {
        if (currFrame.getImage()!=null) {
            if (currFrame.getPos()==0) {
                x -= currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                g.drawImage(currFrame.getImage(), x, y,currFrame.getWidth(),currFrame.getHeight(), null);
            }else {//反向绘制
                Graphics2D g2 = (Graphics2D)g;
                x += currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                transform.setToIdentity();
                transform.scale(-1, 1);
                transform.translate(-x  , y);
                g2.drawImage(currFrame.getImage(),transform,null);
            }
        }
    }
    public void drawflyShadow(Graphics g, int x, int y) {
        if (currFrame.getImage()!=null) {
            if (currFrame.getPos()==0) {
                x -= currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                g.drawImage(currFrame.getImage(), x, y,currFrame.getWidth(),currFrame.getHeight(), null);
            }else {//反向绘制
                Graphics2D g2 = (Graphics2D)g;
                x += currFrame.getRefPixelX();
                y -= currFrame.getRefPixelY();
                transform.setToIdentity();
                transform.scale(-1, 1);
                transform.translate(-x  , y);
                g2.drawImage(currFrame.getImage(),transform,null);
            }
        }
    }
    public static AlphaComposite Composite06=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.6f);
    public void draw(Graphics g, int x, int y, float alpha) {
        Graphics2D g2 = (Graphics2D) g;
        if (alpha==1.0F) {
            draw(g2, x, y);
        }else {
            Composite composite =null;
            try {
                if (alpha==0.6f) {
                    composite =g2.getComposite();
                    g2.setComposite(Composite06);
                }else {
                    composite =g2.getComposite();
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha));
                }
                draw(g2, x, y);
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            } finally {
                if (composite!=null) {
                    g2.setComposite(composite);
                }
            }
            //消除文字锯齿
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            //消除画图锯齿
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        }
    }
    public void updateToTime(long playTime,int dir){
        try {
            if (playTime<0) {
                playTime%=getTime();
                playTime+=getTime();
            }
            Use=1;
            dir%=animCount;
//            playTime/=(Sprite.leixing==0||Sprite.leixing==1) ? 50 : SpriteFactory.ANIMATION_INTERVAL;
//            if (FightingMixDeal.State!= HandleState.USUAL) {
                playTime /= SpriteFactory.ANIMATION_INTERVAL;
//            }else{
//                playTime/=(Sprite.leixing==0||Sprite.leixing==1) ? 50 : SpriteFactory.ANIMATION_INTERVAL;
//            }
//            playTime/=SpriteFactory.ANIMATION_INTERVAL;
            playTime%=frameCount;
            currFrame=frames[(int)(dir*frameCount+playTime)];
            if (load==-1&&currFrame.getImage()==null) {
                load=dir;
                SpriteFactory.addLoad(this);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void updateToTimeRole(long playTime,int dir){
        try {
            if (playTime<0) {
                playTime%=getTime();
                playTime+=getTime();
            }
            Use=1;
            dir%=animCount;

//            playTime/=(Sprite.leixing==0||Sprite.leixing==1) ? 50 : SpriteFactory.ANIMATION_INTERVAL;
//            if (FightingMixDeal.State!= HandleState.USUAL) {
            playTime /= 50;
//            }else{
//                playTime/=(Sprite.leixing==0||Sprite.leixing==1) ? 50 : SpriteFactory.ANIMATION_INTERVAL;
//            }
//            playTime/=SpriteFactory.ANIMATION_INTERVAL;
            playTime%=frameCount;
            currFrame=frames[(int)(dir*frameCount+playTime)];
            if (load==-1&&currFrame.getImage()==null) {
                load=dir;
                SpriteFactory.addLoad(this);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public int getAnimationCount() { return animCount; }
    public int getFrameCount() { return frameCount; }
    public int getTime() { return frameCount*SpriteFactory.ANIMATION_INTERVAL; }
    public SpriteHead getHead() { return head; }
    public void setHead(SpriteHead head) { this.head = head; }
    public int getLoad() { return load; }
    public void setLoad(int load) { this.load = load; }
    public Frame getLoadFrame(int dir) { return frames[dir*frameCount]; }
    public Frame[] getFrames() { return frames; }
    public void removeHead() { //都加载完了 就清除
        this.load=-1;
        for (int i = 0; i < frames.length; i++) {
            if (frames[i].getImage()==null) {setHightMax();return;}
        }
        this.head.remve();
        this.head=null;
        setHightMax();
    }
    public void setHightMax() {
        int max=-99999;
        for (int i = 0; i < frames.length; i++) {
            Frame frame=frames[i];
            if (frame.getImage()==null) { continue; }
            if (frame.getRefPixelY()+frame.getHeight()>max) { max=frame.getRefPixelY()+frame.getHeight(); }
        }
        if (max==-99999) { max=0; }
        hightMax=max;
        if (hightMax>=200) { hightMax-=110; }
    }
    public int getHightMax() { return hightMax; }
    public int getUse() { return Use; }
    public void setUse(int use) { Use = use; }
    public Frame getCurrFrame() { return currFrame; }
    public int getRefPixelX() { return refPixelX; }
    public int getRefPixelY() { return refPixelY; }
    /**旋转共用*/
    public void translate(int dir1,int dir2) {
        for (int i = 0; i < frameCount; i++) {
            Frame frame=frames[dir1*frameCount+i];
            Frame frame2=frames[dir2*frameCount+i];
            frame2.setImage(frame.getImage(),frame.getRefPixelX(),frame.getRefPixelY());
        }
    }

    public void draw(Graphics g, int x, int y, String skillid) {
        if (this.currFrame.getImage() != null) {
            if (this.currFrame.getPos() == 0) {
                x -= this.currFrame.getRefPixelX();
                y -= this.currFrame.getRefPixelY();
                Image image = this.currFrame.getImage();
                if ((skillid.contains("1045.")) || (skillid.contains("1050.")) || (skillid.contains("1020.")) || (skillid.contains("1040.")) || (skillid.contains("1025."))) {
                    int width = (int)Arith.mul(this.currFrame.getWidth(), 1.6D);
                    int height = (int)Arith.mul(this.currFrame.getHeight(), 1.6D);
                    if(skillid.contains("1050.")) {
                    }
                //    System.out.println(x+"--"+y);
                    if(x>0) {
                        x = x;
                    }
                    g.drawImage(image, x, y, width, height, null);
                } else if ( (skillid.contains("1015.")) || (skillid.contains("1010."))) {
                    int width = (int)Arith.mul(this.currFrame.getWidth(), 1.5D);
                    int height = (int)Arith.mul(this.currFrame.getHeight(), 1.5D);
                    g.drawImage(image, x, y, width, height, null);
                } else if (skillid.contains("1030.tcp")) {
                    int width = (int)Arith.mul(this.currFrame.getWidth(), 1.6D);
                    int height = (int)Arith.mul(this.currFrame.getHeight(), 1.6D);
                    g.drawImage(image, x, y, width, height, null);
                } else {
                    g.drawImage(image, x, y, this.currFrame.getWidth(), this.currFrame.getHeight(), null);
                }
            } else {
                Graphics2D g2 = (Graphics2D)g;
                x += this.currFrame.getRefPixelX();
                y -= this.currFrame.getRefPixelY();
                transform.setToIdentity();
                transform.scale(-1.0D, 1.0D);
                transform.translate(-x, y);
                g2.drawImage(this.currFrame.getImage(), transform, null);
            }
        }
    }
}

